package com.atguigu.upp.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.spark.sql.SparkSession;

import java.io.IOException;
import java.io.InputStream;
import java.util.ResourceBundle;


public class UPPUtil
{
    public static SqlSessionFactory createSqlSessionFactory(String config) throws IOException {

        InputStream inputStream = Resources.getResourceAsStream(config);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        return sqlSessionFactory;

    }
    //类似Map
    static ResourceBundle resourceBundle = ResourceBundle.getBundle("config");

    public static String getProperty(String name){

        return resourceBundle.getString(name);

    }

    //创建SparkSession
    public static SparkSession createSparkSession(String appName){
        
         return    SparkSession.builder()
                 .master(getProperty("masterUrl"))
                 .appName(appName)
                 .enableHiveSupport() //读写hive必须设置
                 .getOrCreate();
        
    }

    public static void main(String[] args) {

        System.out.println(getProperty("updbname"));

    }
}
